package com.shf.lease.web.admin.controller.apartment;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shf.lease.entity.CityInfo;
import com.shf.lease.entity.DistrictInfo;
import com.shf.lease.entity.ProvinceInfo;
import com.shf.lease.result.Result;
import com.shf.lease.web.admin.service.CityInfoService;
import com.shf.lease.web.admin.service.DistrictInfoService;
import com.shf.lease.web.admin.service.ProvinceInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.java.Log;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 叶枫
 * @date 2024/7/5.
 */

@Tag(name="地区信息管理")
@RestController
@RequestMapping("/admin/region")
public class ReginInfoController {

    @Resource
    private ProvinceInfoService provinceInfoService;
    @Resource
     private DistrictInfoService districtInfoService;
    @Resource
    private CityInfoService cityInfoService;


    @Operation(summary = "查询省份列表")
    @GetMapping("/province/list")
    public Result<List<ProvinceInfo>> getListProvince(){
        return Result.ok(provinceInfoService.list());
    }

    @Operation(summary = "根据省份id查询市列表")
    @GetMapping("/city/listByProvinceId")
    public Result<List<CityInfo>> getListCityByProvinceId(@RequestParam Long provinceId){
        //构造查询条件
        LambdaQueryWrapper<CityInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(provinceId != null,CityInfo::getProvinceId,provinceId);
        return Result.ok(cityInfoService.list(queryWrapper));
    }
    @Operation(summary = "根据市id查询县区列表")
    @GetMapping("/district/listByCityId")
    public Result<List<DistrictInfo>> getListDistrictByCityId(@RequestParam Long cityId){
        //构造查询条件
        LambdaQueryWrapper<DistrictInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(cityId != null,DistrictInfo::getCityId,cityId);
        return Result.ok(districtInfoService.list(queryWrapper));
    }




}
